//---------------------------------------------------------------
//
//				Supper AB530x
//

#ifndef _PORT_PWM_EX_H_
#define _PORT_PWM_EX_H_

#define LPWM_HANDLE_MAX				3
#define TPWM_HANDLE_MAX				3

typedef struct {
	u32 lpwm_con1;					//LPWMCON 配置
	u16 duty;
} lpwm_handle_strc;


typedef enum {
	LPWM_NONE = 0x00,
	L1PWM_PE4 = 0x11,  //Group1
	L1PWM_PE5,
	L1PWM_PE6,
	L1PWM_PE7,
	
	L2PWM_PB3 = 0x21,  //Group2
	L2PWM_PB4,
	L2PWM_PE0,
	L2PWM_PF2,
	
	L3PWM_PA0 = 0x41,  //Group3
	L3PWM_PA1,
	L3PWM_PA2,
	L3PWM_PA3,
}lpwm_pin;

typedef struct {
	u16 pin_max;
} tpwm_handle_strc;

typedef enum {
	TPWM_NONE = 0x00,
	T3PWM_PB0 = 0x11,  //Group1
	T3PWM_PB1,
	T3PWM_PB2,
	
	T4PWM_PA5 = 0x21,  //Group2
	T4PWM_PA6,
	T4PWM_PA7,
	
	T5PWM_PE1 = 0x41,  //Group3
	T5PWM_PE2,
	T5PWM_PE3,
}tpwm_pin;

typedef struct {
	volatile unsigned long* TMRxCON;
	volatile unsigned long* TMRxCNT;
	volatile unsigned long* TMRxPR;
	volatile unsigned long* TMRxDUTY0;
	volatile unsigned long* TMRxDUTY1;
	volatile unsigned long* TMRxDUTY2;
} tpwm_config_strc;


//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//  Program code example

/*
	lpwm_handler = lpwm_create(LPWM_PE4, LPWM_PE5, LPWM_PE6, LPWM_PE7);
	lpwm_start(lpwm_handler, 1000, 100, 300, 500, 800);
	tpwm_stop(lpwm_handler);
*/

/*
	tpwm_handler = tpwm_create(T3PWM_PB0, T3PWM_PB1, T3PWM_PB2);
	tpwm_start(tpwm_handler, 1000, 100, 300, 500, 800);
	tpwm_stop(tpwm_handler);
*/

//--------------------------------------------------------------------------------------------
//                   LPWM 
extern s8 lpwm_create(lpwm_pin pin1, lpwm_pin pin2, lpwm_pin pin3, lpwm_pin pin4);
extern s8 lpwm_start(s8 fd, u16 period, u16 duty1, u16 duty2, u16 duty3, u16 duty4);
extern s8 lpwm_stop(s8 fd);
extern s8 lpwm_fast_duty(s8 fd, u16 duty1, u16 duty2, u16 duty3, u16 duty4);
extern s8 lpwm_invert(u8 level);
extern s8 lpwm_adjust_cycm(s8 fd, u8 cycm1, u8 cycm2, u8 cycm3, u8 cycm4);
extern s8 lpwm_adjust_step(s8 fd, u8 step1, u8 step2, u8 step3, u8 step4);
extern s8 lpwm_adjust_start(s8 fd);
extern s8 lpwm_adjust_stop(s8 fd);

//--------------------------------------------------------------------------------------------
//					Timer use for PWM
extern s8 tpwm_create(tpwm_pin pin1, tpwm_pin pin2, tpwm_pin pin3);
extern s8 tpwm_start(s8 fd, u16 period, u16 duty1, u16 duty2, u16 duty3);
extern s8 tpwm_stop(s8 fd);
extern s8 tpwm_fast_period(s8 fd, u16 period);
extern s8 tpwm_fast_duty(s8 fd, u16 duty1, u16 duty2, u16 duty3);


#endif
